var config = {
    serverHost : 'http://localhost:8888/'
}

var _util = {
    
    request : function(param){
        var _this = this;
        $.ajax({
            type     : param.method || 'GET',
            url      : param.url || '',
            dataType : param.type || 'json',
            data     : param.data || '',
            success  : function(res){
                if(0 === res.status){
                    typeof param.success === 'function' && param.success(res.data, res.msg);
                }else if(10 === res.status){
                    _this.doLogin();
                }
                else if(1 === res.status){
                    typeof param.error === 'function' && param.success(res.msg);
                }
            },
            error    : function(errMsg){
                //todo 请求失败的提示
                typeof param.error === 'function' && param.error("服务器异常");
            }
        });
    },
    doLogin : function(){
        window.location.href = './account-login.html?redirect='+encodeURIComponent(window.location.href);
    },
    getServerURL : function(path){
        return config.serverHost + path;
    }
};

module.exports = _util;